using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Presenters;
using Dominio;

public partial class CompanyInformation : AbstractView
{
    private CompanyPresenter presenter;
    private Company company;
    public CompanyInformation()
    {
        presenter = new CompanyPresenter();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack) return;
        this.LogedIn();
        this.loadCompany();
        nameinfo.Text = company.Name;
        descriptioninfo.Text = company.Description;
        addressinfo.Text = company.Direccion;
        phoneinfo.Text = company.Telefono;
        contactinfo.Text = company.Contacto;
        rubroinfo.Text = company.Rubro;
    }
    protected void CompanyInformationlink_Click(object sender, EventArgs e)
    {
        Response.Redirect("CompanyInformation.aspx");
    }
    protected void loadCompany()
    {
        this.company = presenter.getCompanyByID(((TestingManager)Session["user"]).Company.IdCompany);
    }
    protected void myAccountlink_Click(object sender, EventArgs e)
    {
        Response.Redirect("myAccountPage.aspx");
    }
    protected void modifyInfo_Click(object sender, EventArgs e)
    {
        modifyInfo.Visible = false;
        saveInfo.Visible = true;

        nametxt.Visible = true;
        nametxt.Text = nameinfo.Text;
        nameinfo.Visible = false;

        descriptiontxt.Visible = true;
        descriptiontxt.Text = descriptioninfo.Text;
        descriptioninfo.Visible = false;

        addresstxt.Visible = true;
        addresstxt.Text = addressinfo.Text;
        addressinfo.Visible = false;

        phonetxt.Visible = true;
        phonetxt.Text = phoneinfo.Text;
        phoneinfo.Visible = false;

        contacttxt.Visible = true;
        contacttxt.Text = contactinfo.Text;
        contactinfo.Visible = false;

        rubrotxt.Visible = true;
        rubrotxt.Text = rubroinfo.Text;
        rubroinfo.Visible = false;
    }
    protected void saveInfo_Click(object sender, EventArgs e)
    {
        modifyInfo.Visible = true;
        saveInfo.Visible = false;
        this.loadCompany();
        this.company.modifyCompany(nametxt.Text, descriptiontxt.Text, addresstxt.Text, phonetxt.Text, contacttxt.Text, rubrotxt.Text);

        presenter.UpdateCompany(this.company);

        nametxt.Visible = false;
        nameinfo.Visible = true;

        descriptiontxt.Visible = false;
        descriptioninfo.Visible = true;

        addresstxt.Visible = false;
        addressinfo.Visible = true;

        phonetxt.Visible = false;
        phoneinfo.Visible = true;

        contacttxt.Visible = false;
        contactinfo.Visible = true;

        rubrotxt.Visible = false;
        rubroinfo.Visible = true;

        nameinfo.Text = company.Name;
        descriptioninfo.Text = company.Description;
        addressinfo.Text = company.Direccion;
        phoneinfo.Text = company.Telefono;
        contactinfo.Text = company.Contacto;
        rubroinfo.Text = company.Rubro;
    }
}
